//
//  AppDelegate.swift
//  EasePods
//
//  Created by 李然 on 2024/4/3.
//

import UIKit
import SwiftDate

@_exported import MoyoungLib
@_exported import EarbudsCommon
@_exported import EarbudsFunctions

#if DEBUG
import FLEX
#endif

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        MinecraftSwiftStarter.enableCache()
        MinecraftSwiftStarter.start()
        Minecraft.modules.application(application, willFinishLaunchingWithOptions: launchOptions)
        return true
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        Minecraft.modules.application(application, didFinishLaunchingWithOptions: launchOptions)
        
        // 设置默认 region
        SwiftDate.defaultRegion = Region(calendar: Calendar.autoupdatingCurrent, zone: Zones.current, locale: Locales.current)
        
        RootViewManager.default.constructRootView()
        
        BluetoothManager.shared.setConfig(isLogEnabel: true)
        Weather.shared.setConfig()
        
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = RootViewManager.default.rootViewController
        window?.makeKeyAndVisible()
        
        if BluetoothManager.shared.isBindedDevice {
            let nav = NavigationController(rootViewController: HomeViewController())
            RootViewManager.default.transition(vc: nav)
        } else {
            let nav = NavigationController(rootViewController: BoundHomeViewController())
            RootViewManager.default.transition(vc: nav)
        }
        
        self.showFlex()
        
        return true
    }

}

extension AppDelegate {
    
    func showFlex() {
        #if DEBUG
        FLEXManager.shared.showExplorer()
        #endif
    }
}
